﻿<%@ WebHandler Language="C#" Class="Down" %>
using System;
using System.Web;

public class Down : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        if (context.Request.QueryString["f"] == null)
        {
            context.Response.Write("参数出出错.");
            context.Response.End();
        }
        string FileName = context.Request.QueryString["f"].ToString();
        if (FileName == "") { context.Response.Write("参数出错."); context.Response.End(); }

        string Path = context.Server.MapPath(FileName);
        System.IO.FileInfo F = new System.IO.FileInfo(Path);
        if (F.Exists)
        {
            context.Response.Clear();
            context.Response.AddHeader("Content-Disposition", "attachment; filename=" + F.Name);
            context.Response.AddHeader("Content-Length", F.Length.ToString());
            context.Response.ContentType = "application/octet-stream";
            context.Response.Filter.Close();
            context.Response.WriteFile(F.FullName);
            context.Response.End();
        }
        else
        {
            context.Response.Write("你所下载的文件不存在.");
            context.Response.End();
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}